<?php

namespace App\Http\Controllers;

use App\Models\GameAreaInfo;
use App\Models\TGameAreaInfo;
use Illuminate\Http\Request;
use App\Http\Libraries\Page;
use Auth;

class OrderController extends Controller
{
    protected $param = array();

    public function __construct(Request $request)
    {
        $page = $request->page ? $request->page : 1;

        $this->param = array(
            'per_page' => env('PER_PAGE'),                     //一页多少条
            'page' => $page,                              //当前第几页
        );
    }



    //首页
    public function index()
    {
        $_order_index = 'am-active';
        return view('order.index', compact('_order_index'));
    }


    //租赁订单列表
    public function lease(Request $request)
    {

        //获取接口数据
        $url = env('ORDERS_API_URL') . '/lease';
        $result = _curlRequest($url, 'get', $this->param);
        $order_leases = $result['data']['order_list'];

        //分页
        $p = new Page($order_leases['total'], $order_leases['per_page'], '', '/lease?');
        $page = $p->show();

        $_order_lease = 'am-active';
        return view('order.lease.lease', compact('_order_lease', 'order_leases', 'page'));
    }

    //租赁订单详情
    public function lease_detail($id)
    {
        //获取接口数据
        $url = env('ORDERS_API_URL') . '/lease/' . $id;
        $result = _curlRequest($url, 'get');
        $lease_detail = $result['data']['order'];

        $_order_lease = 'am-active';
        return view('order.lease.lease_detail', compact('_order_lease', 'lease_detail'));
    }

    //维权订单列表
    public function arbitration()
    {
        //获取接口数据
        $url = env('ORDERS_API_URL') . '/arbitration';


        $result = _curlRequest($url, 'get', $this->param);

        $order_arbitrations = $result['data']['arbitration_list'];


        $p = new Page($order_arbitrations['total'], $order_arbitrations['per_page'], '', '/arbitration?');
        $page = $p->show();

        $_order_arbitration = 'am-active';
        return view('order.arbitration.arbitration', compact('_order_arbitration', 'page', 'order_arbitrations'));
    }

    //维权订单详情
    public function arbitration_detail($id)
    {
        //获取接口数据
        $url = env('ORDERS_API_URL') . '/arbitration/' . $id;
        $result = _curlRequest($url, 'get');

//        return $result;
        $arbitration_detail = $result['data'];
//        return $arbitration_detail['addto_list'];
        $_order_arbitration = 'am-active';
        return view('order.arbitration.arbitration_detail', compact('_order_arbitration', 'arbitration_detail'));
    }

    //客服仲裁订单
    public function arbitration_servicedeal(Request $request, $id)
    {

        $querys = array(
            'arbitration_id' => $id,
            'addto_explians' => $request->addto_explians,
            'service_user_id' => Auth::user()->id,
            'is_agree' => $request->is_agree,
        );

        $url = env('ORDERS_API_URL') . '/arbitration/servicedeal';
        $result = _curlRequest($url, 'post', $querys);

        if ($result['status'] == 1) {
            return back()->with('notice', $result['msg']);
        } else {
            return back()->with('alert', $result['msg']);
        }

    }

















//    //购买订单
//    public function buy(Request $request)
//    {
//        $_buy = 'am-active';
//
//        $games = TGameAreaInfo::where('parent_id', 0)->select('id', 'game_name')->get();
//
//        return view('order.buy', compact('_buy', 'buys', 'games'));
//    }
//
//
//    public function leveling()
//    {
//        $_leveling = 'am-active';
//        $parent_game_areas = GameAreaInfo::where('grade', 2)->select('id', 'game_name')->get();
//        $game_areas = GameAreaInfo::where('grade', 3)->select('id', 'game_name')->get();
//
//        return view('order.leveling', compact('_leveling', 'parent_game_areas', 'game_areas'));
//    }
//
//    public function leveling_referee()
//    {
//        $_leveling_referee = 'am-active';
//        $parent_game_areas = GameAreaInfo::where('grade', 2)->select('id', 'game_name')->get();
//        $game_areas = GameAreaInfo::where('grade', 3)->select('id', 'game_name')->get();
//
//        return view('order.leveling_referee', compact('_leveling_referee', 'parent_game_areas', 'game_areas'));
//    }
//
//
//    public function traffic()
//    {
//        $_traffic = 'am-active';
//        return view('order.traffic', compact('_traffic'));
//    }
//
//    public function q_coin()
//    {
//        $_q_coin = 'am-active';
//        return view('order.q_coin', compact('_q_coin'));
//    }
//
//
//    public function reward()
//    {
//        $_reward = 'am-active';
//        $parent_game_areas = GameAreaInfo::where('grade', 2)->select('id', 'game_name')->get();
//        $game_areas = GameAreaInfo::where('grade', 3)->select('id', 'game_name')->get();
//
//        return view('order.reward', compact('_reward', 'parent_game_areas', 'game_areas'));
//    }
//
//
//    public function game_coin()
//    {
//        $_game_coin = 'am-active';
//        return view('order.game_coin', compact('_game_coin'));
//    }
//
//    public function compensate()
//    {
//        $_compensate = 'am-active';
//        return view('order.compensate', compact('_compensate'));
//    }
//
//
//    public function item()
//    {
//        return view('order.item');
//    }

}
